package com.senyint.hip.fhir.web;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.client.impl.GenericClient;
import com.senyint.hip.fhir.config.TempData;
import com.senyint.hip.fhir.interceptor.BufferResponseInterceptor;
import com.senyint.hip.fhir.interceptor.CaptureInterceptor;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * *******description*******
 * <p>
 * *************************
 *
 * @author ChenPan
 * @date 2018/10/30 11:16
 */
public abstract class FhirBaseController {

    @Autowired
    TempData tempData;

    protected FhirContext ctx = FhirContext.forR4();

    protected GenericClient newClient(String url, CaptureInterceptor interceptor) {
        /*String serverBase = "http://localhost:8081/fhir2";*/

        GenericClient client = (GenericClient) ctx.newRestfulGenericClient(url);
        client.registerInterceptor(new BufferResponseInterceptor());

        client.setKeepResponses(true);
        client.registerInterceptor(interceptor);

        return client;
    }
}
